<template>
<el-col :span="6">
  <el-form-item :label="selectName" :prop="propBind">
    <el-select :value="prop" placeholder="请选择" @change="onSelectChange">
      <el-option
          v-for="item in renderList"
          :key="item.value"
          :label="item.label"
          :value="item.value">
      </el-option>
    </el-select>
  </el-form-item>
</el-col>
</template>

<script>
/**
* @description: 渲染下拉框
* @param {type} selectName:下拉框命名
* @param {type} selectList:下拉框渲染列表
* @param {type} prop:下拉框选中项
* @return: onSelectChange: Function(val)：选中后向父组件传入当前选中项
*/
export default {
  name: 'SubSelect',
  props: {
    selectName: {
      required: true,
      type: String,
      default: ''
    },
    list: {
      required: true,
      type: [Array, Number, String],
      default: () => []
    },
    prop: {
      type: [String, Number]
    }
  },
  data () {
    return {}
  },
  created: function () {},
  methods: {
    // subject change
    onSelectChange (val) {
      this.$emit('onSelectChange', val)
    }
  },
  computed: {
    renderList () {
      return this.list ? this.list : []
    },
    propBind () {
      if (!this.prop) {
        return ''
      } else if (typeof this.prop === 'number') {
        return String(this.prop)
      }
      return this.prop
    }
  }
}
</script>

<style scoped>
.el-select {
  min-width: 100%;
}
</style>
